package restlet;

import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.Request;
import org.restlet.Response;

public class Component_resource {
	public static void main(String[] args) throws Exception {
		// Create a new Restlet component and add a HTTP server connector to it
		Component component = new Component();
		component.getServers().add(Protocol.HTTP, 8182);

		// Create a new tracing Restlet
		Restlet restlet = new Restlet() {
			@Override
			public void handle(Request request, Response response) {
				// Print the requested URI path
				String message = "Resource URI  : " + request.getResourceRef() + '\n' + "Root URI      : "
						+ request.getRootRef() + '\n' + "Routed part   : " + request.getResourceRef().getBaseRef()
						+ '\n' + "Remaining part: " + request.getResourceRef().getRemainingPart();
				response.setEntity(message, MediaType.TEXT_PLAIN);
			}
		};

		// Then attach it to the local host
		component.getDefaultHost().attach("/trace", restlet);
		component.start();
	}
}
